package com.scgl.process.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.scgl.process.domain.ScglLog;
import com.scgl.process.service.IScglLogService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 生产日志Controller
 *
 * @author ruoyi
 * @date 2024-11-04
 */
@RestController
@RequestMapping("/log")
public class ScglLogController extends BaseController
{
    @Autowired
    private IScglLogService scglLogService;

    /**
     * 查询生产日志列表
     */
    @RequiresPermissions("process:log:list")
    @GetMapping("/list")
    public TableDataInfo list(ScglLog scglLog)
    {
        startPage();
        List<ScglLog> list = scglLogService.selectScglLogList(scglLog);
        return getDataTable(list);
    }

    /**
     * 导出生产日志列表
     */
    @RequiresPermissions("process:log:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScglLog scglLog)
    {
        List<ScglLog> list = scglLogService.selectScglLogList(scglLog);
        ExcelUtil<ScglLog> util = new ExcelUtil<ScglLog>(ScglLog.class);
        util.exportExcel(response, list, "生产日志数据");
    }

    /**
     * 获取生产日志详细信息
     */
    @RequiresPermissions("process:log:query")
    @GetMapping(value = "/{serial}")
    public AjaxResult getInfo(@PathVariable("serial") Long serial)
    {
        return success(scglLogService.selectScglLogBySerial(serial));
    }

    /**
     * 新增生产日志
     */
    @RequiresPermissions("process:log:add")
    @Log(title = "生产日志新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScglLog scglLog)
    {
        return toAjax(scglLogService.insertScglLog(scglLog));
    }

    /**
     * 修改生产日志
     */
    @RequiresPermissions("process:log:edit")
    @Log(title = "生产日志修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScglLog scglLog)
    {
        return toAjax(scglLogService.updateScglLog(scglLog));
    }

    /**
     * 删除生产日志
     */
    @RequiresPermissions("process:log:remove")
    @Log(title = "生产日志删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{serials}")
    public AjaxResult remove(@PathVariable Long[] serials)
    {
        return toAjax(scglLogService.deleteScglLogBySerials(serials));
    }
}
